﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Jian.Vubackup.MySql
{
    public class GroupItem
    {
        public string GroupName { get; set; }
        public List<FileInfoItem> FileList { get; set; }
        public GroupItem(string groupName)
        {
            GroupName = groupName;
            FileList = new List<FileInfoItem>();
        }

        public void Clear()
        {
            if (FileList != null && FileList.Count > 0)
            {
                FileList = FileList.OrderByDescending(t => t.Time).ToList();
                for (int i = 0; i < FileList.Count; i++)
                {
                    if (i > 1)
                    {
                        FileInfoItem file = FileList[i];
                        if (file.File != null)
                        {
                            if (File.Exists(file.File.FullName))
                            {
                                file.File.Delete();
                            }
                        }
                    }
                }
            }
        }
    }
}
